package cn.fanyamin.web.struts;

import java.util.List;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.apache.commons.lang.math.NumberUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import cn.fanyamin.business.ItemService;
import cn.fanyamin.domain.UserCategory;
import cn.fanyamin.domain.Item;
import cn.fanyamin.domain.User;

public class LifeAction extends ItemAction {
	private static Log logger = LogFactory.getLog(ItemAction.class);

	public ActionForward list(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) {
		ItemService itemService = getWebApp().getItemService();
		User user = getUserFromSession(request);
		
		int itemType = NumberUtils.toInt(request.getParameter("itemType"));
		List<Item> itemList = null;
		if(itemType == 0) {
			itemList = itemService.getCheckList(user.getUserID());
		} else {
			Item item = new Item();
	        item.setUserID(user.getUserID());
	        item.setItemType(itemType);
	        itemList = itemService.findItems(item);
		}
		
        
		setCategories(request, UserCategory.CATEGORY_TYPE_TASK);
		setItemTypes(request);
		
	    
	    request.setAttribute("itemList", itemList);
		logger.info("itemList: " + itemList);
        return mapping.findForward("list");

	}
	
	
}
